
const registerBox = document.querySelector('.register');
const registerA = document.querySelector('.register-a');
const loginBox = document.querySelector('.login');
const loginA = document.querySelector('.login-a');


// 点击跳转到注册页面
loginA.addEventListener('click', function () {
    registerBox.style.display = 'block'
    loginBox.style.display = 'none'
})
// 点击跳转到登陆页面
registerA.addEventListener('click', function () {
    loginBox.style.display = 'block'
    registerBox.style.display = 'none'
})

// 注册事件
registerBox.querySelector('form').addEventListener('submit', function (e) {
    e.preventDefault()
    const data = $(this).serialize()
    axios.post('/api/register', data)
        .then(result => {
            if (result.data.code === 0) {
                // console.log(result);
                toastr.success('注册成功')
                registerA.click()
            } 
        })
})

loginBox.querySelector('form').addEventListener('submit', function (e) {
    e.preventDefault()
    const data = $(this).serialize()
    axios.post('/api/login',data)
    .then(result=>{
        console.log(result);
        if(result.data.code===0){
            localStorage.setItem('token82',result.data.token)
            toastr.success(result.data.message)
            setTimeout(() => {
                location.href='./index.html'
            }, 1500);
        }
       
    })
})